﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml.Linq;

namespace DSCop.Core.Test
{
    public class BaseTest
    {
        public Stream LoadTestXml(Assembly asm, string filePath, string fileName)
        {
            Stream xmlStream = asm.GetManifestResourceStream(filePath + fileName);
            if (xmlStream == null)
            {
                throw new ArgumentException("Invalid file name " + filePath + fileName);
            }

            return xmlStream;
        }

        public XElement LoadTestXElement(Assembly asm, string filePath, string fileName)
        {
            Stream xmlStream = LoadTestXml(asm, filePath, fileName);
            XElement testXElement = XElement.Load(xmlStream);

            return testXElement;
        }

        public IList<RuleViolation> TestRule<T>(XElement jobXElement) where T : IDSRule, new()
        {
            IDSRule rule = new T();
            IList<RuleViolation> violations = rule.ValidateJob(jobXElement);

            return violations;
        }
    }
}
